﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Micrhard.FMCG.Server.Validator;
using Microhard.Core.DBUtility;

namespace Micrhard.FMCG.Server.Models
{
    [FluentValidation.Attributes.Validator(typeof(SubKAValidator))]
    public class SubKAModel : BasePermissionModel
    {
        [ModelPKID]
        public Guid SubID { set; get; }
        public Guid KAID { set; get; }
        public string KAName { set; get; }
        public string KACode { set; get; }
        public string Name { set; get; }
        public string Address { set; get; }
        public string Province { set; get; }
        [ModelReadTxtFromoCache(PCDName = PCD.Province, IDFieldName = "Province")]
        public string ProvinceDisplayTxt { set; get; }
        public string City { set; get; }
        [ModelReadTxtFromoCache(PCDName = PCD.City, IDFieldName = "City")]
        public string CityDisplayTxt { set; get; }
        public string Contractor { set; get; }
        public string Cellphone { set; get; }
        public string CustomerCode { set; get; }

        public Guid EmployeeID { set; get; }
        public Guid KAMonitorID { set; get; }
        public List<EmployeeModel> SalerEmployees { set; get; }
        public List<EmployeeModel> MonitorEmployees { set; get; }

        private string _salerName;
        public string SalerNames
        {
            get
            {
                StringBuilder names = new StringBuilder();
                if (SalerEmployees != null)
                {
                    SalerEmployees.ForEach(e =>
                    {
                        names.Append(e.Name);
                        names.Append(",");
                    });
                }
                return names.ToString();
            }
            set { this._salerName = value; }
        }

        private string _monitorNames;
        public string MonitorNames
        {
            get
            {
                StringBuilder names = new StringBuilder();
                if (MonitorEmployees != null)
                {
                    MonitorEmployees.ForEach(e =>
                    {
                        names.Append(e.Name);
                        names.Append(",");
                    });
                }
                return names.ToString();
            }
            set
            {
                this._monitorNames = value;
            }
        }

        public double Baidulng { set; get; }
        public double Baidulat { set; get; }

        /// <summary>
        /// 本月累计拜访次数
        /// </summary>
        public int CheckTimes { set; get; }
        /// <summary>
        /// 累计销量
        /// </summary>
        public decimal AmountSaleVolumn { set; get; }
        /// <summary>
        /// 销售数量
        /// </summary>
        public double SaleCount { set; get; }
        /// <summary>
        /// 库存数量
        /// </summary>
        public double StoreCount { set; get; }
        /// <summary>
        /// 库存金额
        /// </summary>
        public decimal StoreAmount { set; get; }
        /// <summary>
        /// 同比销量
        /// </summary>
        public decimal TBAmountSaleVolumn { set; get; }
        public double TB
        {
            get
            {
                if (TBAmountSaleVolumn > 0)
                {
                    return ((double)(AmountSaleVolumn - TBAmountSaleVolumn) / (double)TBAmountSaleVolumn) * 100;
                }
                return 0;
            }
        }
        /// <summary>
        /// 环比销量
        /// </summary>
        public decimal HBAmountSaleVolumn { set; get; }
        public double HB
        {
            get
            {
                if (HBAmountSaleVolumn > 0)
                {
                    return ((double)(AmountSaleVolumn - HBAmountSaleVolumn) / (double)HBAmountSaleVolumn) * 100;
                }
                return 0;
            }
        }
        public DateTime ReportQueryForBeginDate { set; get; }
        public string QueryBeginDateForDetail
        {
            get
            {
                return this.ReportQueryForBeginDate.ToString("yyyy-MM-dd");
            }
        }
        public DateTime ReportQueryForEndDate { set; get; }
        public string QueryEndDateForDetail
        {
            get
            {
                return this.ReportQueryForEndDate.ToString("yyyy-MM-dd");
            }
        }
    }
}
